﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace EPiServer
{
    public partial class TestBandwidth : TemplatePage
    {
     
        protected void Page_Load(object sender, EventArgs e)
        {
            string url = Request.QueryString["url"];

            textbox.TextChanged += new EventHandler(textbox_TextChanged);

            ViewState["urltoredirect"] = url;

            Page.ClientScript.RegisterClientScriptBlock(typeof(TestBandwidth), "buttonsubmit", String.Format("function submitResult(value){{ document.getElementById('{0}').value = value; {1}; }}",textbox.ClientID, Page.ClientScript.GetPostBackEventReference(textbox, "")), true);
        }

        void textbox_TextChanged(object sender, EventArgs e)
        {
            string value = textbox.Text;

            string CookieName = "bandwidth";

            try
            {
                HttpCookie cookie = new HttpCookie(CookieName);
                Response.Cookies.Clear();
                Response.Cookies.Add(cookie);
                cookie.Values.Add("bandwidth", value);
                Response.Cookies[CookieName].Expires = DateTime.Now.AddHours(1);
            }
            catch { }

            Server.Transfer((string)ViewState["urltoredirect"]);
           
        }
    }
}